package com.wechat.controller;

import com.wechat.annotation.GlobalInterceptor;
import com.wechat.entity.query.UserInfoQuery;
import com.wechat.entity.vo.PaginationResultVO;
import com.wechat.entity.vo.ResponseVO;
import com.wechat.service.UserInfoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

@RestController("adminUserInfoController")
@RequestMapping("/admin")
public class AdminUserInfoController extends ABaseController{
    @Resource
    UserInfoService userInfoService;

    /**
     * 加载管理员用户列表---分页查询-URL查询参数
     * @param userQuery
     * @return
     */
    @GetMapping("/loadUser")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO loadUser(UserInfoQuery userQuery) {//这里不需要@RequestBody注解，因为参数是URL查询参数，Spring MVC 会将传过来的参数绑定到对象属性上
        userQuery.setOrderBy("create_time desc");
        PaginationResultVO resultVO = userInfoService.findListByPage(userQuery);
        return getSuccessResponseVO(resultVO);
    }

    /**
     * 修改用户状态
     * @param status
     * @param userId
     * @return
     */
    @RequestMapping("/updateUserStatus")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO updateUserStatus(@NotNull Integer status, @NotEmpty String userId) {
        userInfoService.updateUserStatus(status, userId);
        return getServerErrorResponseVO(null);
    }

    /**
     * 强制下线
     * @param userId
     * @return
     */
    @RequestMapping("/forceOffLine")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO forceOffLine(@NotEmpty String userId) {
        userInfoService.forceOffLine(userId);
        return getServerErrorResponseVO(null);
    }



}
